package com.example.android427;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.android427.Fragment.gerenFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShezhiActivity extends AppCompatActivity {
    private ListView listview;
    private MyBaseAdapter adapter;


    private ArrayList<String> mlist = new ArrayList<String>();
    //设置参照物的hashmap 来保证switchbuttom不会出现错乱 一定要保证  map和list长度一致
    private Map<String, Boolean> selectedMap = new HashMap<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shezhi);

        Button sehzhi = (Button)findViewById(R.id.shezhi_b1);
        sehzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initList();
        listview = (ListView) findViewById(R.id.listview);
        adapter = new MyBaseAdapter(ShezhiActivity.this, mlist, selectedMap);
        listview.setAdapter(adapter);
        

        adapter.OnSetOnClickDialogListener(new MyBaseAdapter.SetOnClickDialogListener() {
            @Override
            public void onClickDialogListener(int position, boolean boolClick) {
                selectedMap.put(mlist.get(position), boolClick);

                //map的遍历
                for (Map.Entry<String, Boolean> entry : selectedMap.entrySet()) {
                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
                }
            }
        });
    }


    private void initList() {
        mlist.add("\t只有WIFI时下载");
        //=====
        mlist.add("\t文津经典诵读消息推送");
        mlist.add("\t新闻、公告、专题消息推送");
        mlist.add("\t讲座预告、图书到期、欠费提醒");
        mlist.add("\t清除本地缓存");
        for (int i = 0; i < mlist.size(); i++) {
            selectedMap.put(mlist.get(i), false);
        }
    }

}
